#!/bin/python
#-*- coding:utf-8 -*-
# Filename:    main.py
# Revision:    1.0
# Date:        2012-06-14
# Author:      simonzhang
# web:         www.simonzhang.net
# Email:       simon-zzm@163.com
##########
# 2012-11-8 add download Handler
### END INIT INFO
import os
import sys
import random
import tornado.ioloop
import tornado.locale
import tornado.web
from dbmodel import *
from interface import *


def get_key_ip():
    key_ip_file = open("key_ip.txt", "rb").readlines()
    ip_list = []
    for i in key_ip_file:
        ip_list.append(i[:-1])
    return ip_list



class MainHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        _get_user = self.check_user()
        _domain, _title = if_get_domain_title()
        _get_user_left_menu = if_get_user_left_menu(_get_user)
        _status = 0
        last_date = odb_get_last_date()[0]['lastdate']
        from version import db_use_now_date
        if str(last_date) != str(db_use_now_date):
            _status = 1
        self.render("templates/index.html", domain=_domain, \
                                            title=_title, \
                                            username = _get_user, \
                                            items=_get_user_left_menu, \
                                            version_status = _status, \
                                            lastdate = last_date, \
                                            nowdate = db_use_now_date)
    def post(self):
        self.clear_all_cookies()
        self.redirect("/")

